﻿using OnDash.Windowing.GraphicsLibraryFramework;

namespace OnDash.Windowing.Desktop;

public unsafe struct GlfwGraphicsContext : IGlfwGraphicsContext
{
    private readonly Window* _windowPtr;
    public IntPtr WindowPtr => (IntPtr)_windowPtr;

    public GlfwGraphicsContext(Window* windowPtr)
    {
        _windowPtr = windowPtr;
    }

    public bool IsCurrent => Glfw.GetCurrentContext() == _windowPtr;

    private int _swapInterval;

    public int SwapInterval
    {
        get => _swapInterval;
        set
        {
            Glfw.SwapInterval(value);
            _swapInterval = value;
        }
    }

    public void SwapBuffers()
    {
        Glfw.SwapBuffers(_windowPtr);
    }

    public void MakeCurrent()
    {
        Glfw.MakeContextCurrent(_windowPtr);
    }

    public void MakeNoneCurrent()
    {
        Glfw.MakeContextCurrent(null);
    }
}